<?php

include_once "funct.php";

if (!isset($_GET["id"], $_GET["r"], $_SESSION["user"]))
	iesire();
clean($_GET["id"]);
clean($_GET["r"]);
$room = room($_GET["id"]);
if ($room === false)
	iesire();

if (ok_vote($room["id"], $_SESSION["user"])) {
	mysql_query("insert into " . $db["votes"] . " set room='" . $_GET["id"] . "', user='" . $_SESSION["user"] . "'");
	if ($_GET["r"] == 1)
		$room["votes"] = $room["votes"] + 1;
	elseif ($_GET["r"] == 2)
		$room["votes2"] = $room["votes2"] + 1;
	mysql_query("update " . $db["rooms"] . " set votes='" . $room["votes"] . "', votes2='" . $room["votes2"] . "' where id='" . $room["id"] . "'");
}	
location("judge_em");
?>
